<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>完成bind函数（解决绑定事件的兼容性问题）</title>
</head>
<body>
    <button style="width: 100px; height:50px; background-color:aquamarine" id="btn01">btn01按钮</button>
</body>
</html>
<script>
    /*

    */

    var btn01 = document.getElementById("btn01");
    function bind(obj,eventStr,callback){

        if(obj.addEventListener){
            obj.addEventListener(eventStr,callback,false);
        }else{
            obj.attachEvent("on"+eventStr,function(){
                callback.call(obj);
            });
        }

    }
    bind(btn01,"click",function(){
        alert("1223");
        alert(this);
    });

    /*
        这里的 callback.call(obj);

        相当于 function d(){
            alert(this);
        }
        d.call(obj);
        
    */

    // 举例
    /*
    var obj={
        name:"孙悟空",
        age : 18
    };
    function fun(objs,callbacks){
        callbacks.call(objs);
    }
    fun(obj,function(){
        alert(this.name);
    });
    */
</script>